<template>
  <div class="search-box clearfix">
    <div class="clearfix">
      <input v-model="search" type="text" class="search-input" :placeholder="placeholder" @keydown.enter.stop="handleSearch">
      <button class="search-btn" @click="handleSearch">{{ searchText }}</button>
    </div>
  </div>
</template>
<script>
export default {
  props: {
    searchKey: {
      type: String,
      default() {
        return ''
      }
    },
    placeholder: {
      type: String,
      default() {
        return '请输入搜索内容'
      }
    },
    searchText: {
      type: String,
      default() {
        return '搜索'
      }
    }
  },
  data() {
    return {
      search: ''
    }
  },
  mounted() {
    this.search = this.searchKey
  },
  methods: {
    handleSearch() {
      this.$emit('search', this.search)
    }
  }
}
</script>
<style lang="scss" rel="stylesheet/scss" scoped>
.search-box {
  float: right;
}

.search-box .search-input {
  width: 254px;
  height: 36px;
  border: 1px solid #dfdfdf;
  margin-right: 10px;
  padding: 0 10px;
  background-color: #fff;
  border-radius: 8px;
  -webkit-border-radius: 8px;
  -moz-border-radius: 8px;
}

.search-box .search-input:focus {
  outline: none;
  border-color: #4269c8;
}

.search-box .search-btn {
  padding: 0 17px;
  height: 36px;
  border: 0;
  color: #fff;
  background-color: #4269c8;
  cursor: pointer;
  border-radius: 8px;
  -webkit-border-radius: 8px;
  -moz-border-radius: 8px;
}
.clearfix {
  height: 36px;
}
</style>
